
# 设置中文字体支持
plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体
plt.rcParams['axes.unicode_minus'] = False    # 正常显示负号

# 数据准备
datasets = ['MovieLens-1M', 'Amazon Electronics']
methods = ['MF', 'DICE', 'Ours']

# Coverage@50数据 (表3数据)
coverage_data = {
    'MovieLens-1M': [0.29, 0.37, 0.51],
    'Amazon Electronics': [0.18, 0.26, 0.39]
}

# 创建专业图表
plt.figure(figsize=(5, 3), dpi=300)

# 设置颜色和标记样式
colors = ['#1f77b4', '#ff7f0e']
markers = ['o', 's']
line_styles = ['-', '--']

# 绘制折线
for i, dataset in enumerate(datasets):
    plt.plot(methods, coverage_data[dataset], 
             label=dataset, 
             color=colors[i], 
             marker=markers[i], 
             markersize=10,
             linewidth=2.5,
             linestyle=line_styles[i])

# 添加数据标签
for dataset in datasets:
    for j, method in enumerate(methods):
        plt.text(j, coverage_data[dataset][j] + 0.01, 
                 f'{coverage_data[dataset][j]:.2f}', 
                 ha='center', va='bottom',
                 fontsize=10, fontweight='bold',
                 color=colors[datasets.index(dataset)])

# 设置标题和标签
# plt.title('不同数据集上Coverage@50对比', fontsize=14, fontweight='bold', pad=15)
plt.xlabel('Method', fontsize=13, fontweight='bold')
plt.ylabel('Coverage@50', fontsize=13, fontweight='bold')

# 设置Y轴范围
plt.ylim(0.15, 0.55)

# 添加网格线（浅灰色，虚线）
plt.grid(True, linestyle='--', alpha=0.3, color='gray')

# 添加图例
plt.legend(loc='upper left', fontsize=10)

# 突出本文方法(Ours)
plt.axvline(x=2, color='red', linestyle=':', alpha=0.5)
# plt.text(2.05, 0.25, '本文方法', rotation=90, 
#          fontsize=10, color='red', va='center')

# 添加数据说明
# plt.text(0.5, 0.16, 'Amazon Electronics数据稀疏性更高(Gini=0.81)', 
#          fontsize=9, color='#ff7f0e', ha='center')
# plt.text(0.5, 0.53, 'MovieLens-1M用户评分更均匀(Gini=0.65)', 
#          fontsize=9, color='#1f77b4', ha='center')

# 优化布局
plt.tight_layout()

# 保存高质量图片
plt.savefig('coverage_comparison.png', bbox_inches='tight', dpi=300)
plt.show()
